package com.medusa.aps.business.modules.board.model.bo;

import cn.hutool.core.collection.CollUtil;
import com.medusa.aps.business.global.model.o.RangeDate;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * @author 张治保
 * @since 2024/1/6
 */
@ToString
@Getter
@Accessors(chain = true)
public class DateWorkDuration {

    /**
     * 组成当日工作时长的时间段
     */
    private final List<RangeDate> times = CollUtil.newArrayList();
    /**
     * 关联订单号
     */
    private final Set<String> orders = CollUtil.newHashSet();
    /**
     * 排程当日工作时长
     */
    private Duration duration = Duration.ZERO;

    public DateWorkDuration add(String orderNumber, RangeDate time) {
        this.orders.add(orderNumber);
        this.times.add(time);
        this.duration = this.duration.plus(time.toDuration());
        return this;
    }

    public DateWorkDuration add(DateWorkDuration dateDuration) {
        this.orders.addAll(dateDuration.getOrders());
        this.times.addAll(dateDuration.getTimes());
        this.duration = this.duration.plus(dateDuration.duration);
        return this;
    }

    public DateWorkDuration add(String orderNumber, LocalDateTime startTime, LocalDateTime endTime) {
        return this.add(orderNumber, new RangeDate().setStartTime(startTime).setEndTime(endTime));
    }

}
